package com.steak.system.controller.student;

import com.auth0.jwt.JWT;
import com.steak.system.common.base.BaseController;
import com.steak.system.common.exception.BusinessException;
import com.steak.system.common.resultType.Result;
import com.steak.system.pojo.dto.ApplyDTO;
import com.steak.system.pojo.dto.RecruitDTO;
import com.steak.system.service.student.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RequestMapping("/student")
@RestController
public class StudentController extends BaseController {
    @Autowired
    private StudentService studentService;

    /**
     * 查询所有招聘表
     * @param page
     * @return
     */
    @GetMapping("/getAllRecruitCheckIsOk")
    public Result getAllRecruitCheckIsOk(@RequestParam int page){
        List<RecruitDTO> list = studentService.getAllRecruitCheckIsOk(page);
        return Result.create(list);
    }

    /**
     * 保存申请表
     * @param request
     * @param recruitId
     * @param self
     * @return
     */
    @PostMapping("/saveApply")
    public Result saveApply(HttpServletRequest request , @RequestParam int recruitId , @RequestParam String self){
        String token = request.getHeader("TOKEN");
        String userId = JWT.decode(token).getClaim("userId").asString();
        studentService.saveApply(recruitId,self,userId);
        return Result.create(null);
    }

    /**
     * 根据学生的ID获取他的申请表信息
     * @return
     */
    @GetMapping("/getApplyByUserId")
    public Result getApplyByUserId(HttpServletRequest request) throws BusinessException {
        String token = request.getHeader("TOKEN");
        String userId = JWT.decode(token).getClaim("userId").asString();
        ApplyDTO applyDTO = studentService.getApplyByUserId(userId);
        return Result.create(applyDTO);
    }
}
